<%-- 
    Document   : index
    Author     : Jagadeesh
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="model.UserBean" %>
<%@page import="java.sql.*"%>
<%@page import="database.DBClass"%>
<%@page import="java.util.List"%>
<link rel="stylesheet" href="css/bootstrap.css">
<%
    if (session.getAttribute("userName") == null) {

        RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
        rd.forward(request, response);
    }

    UserBean bean;
    bean = new UserBean();
    if (request.getAttribute("error") != null) {
        bean = (UserBean) request.getAttribute("error");
    }
    if (request.getAttribute("updateuser") != null) {
        bean = (UserBean) request.getAttribute("updateuser");
    }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="js/show.js"></script>

        <title>Tambah Data Senjata</title>
    </head>
    <body>
        <img src="gambar/head2.PNG" id="logo" alt="logo">
        <center>
            <h1> </h1>

            <form method="post" action="ControllerServlet">

                <TABLE border="0"width="600px">
                    <TR>
                        <TD width="150px">ID Senjata:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="idSenjata" value="<%=bean.getIdSenjata()%>">

                        </TD>

                    </TR>
                    <TR>
                        <TD width="150px">Nama Senjata:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="namaSenjata" value="<%=bean.getNamaSenjata()%>" >
                        </TD>

                    </TR>
                    <TR>
                        <TD width="150px">Jenis:</TD>
                        <TD>

                            <select name='jenis' onchange="showJenis(this.value)">  
                              <option value="<%= bean.getJenis()%>"><%= bean.getNamaJenis()%></option>  
                                
                                <%
                                    DBClass dbobject = new DBClass();
                                    List list = dbobject.getJenis();
                                    request.setAttribute("list", list);
                                    List list2 = (List) request.getAttribute("list");
                                    if (list2 != null) {
                                        for (int i = 0; i < list2.size(); i++) {
                                            UserBean ubean = (UserBean) list2.get(i);
                                %>
                                <option value="<%=ubean.getIdJenis()%>"><%= ubean.getNamaJenis()%></option>  
                                <%
                                        }
                                    }
                                %>
                            </select>  

                        </TD>

                    </TR>
                    <TR>
                        <TD width="150px">Gudang:</TD>
                        <TD>
                            <select name='idGudang' onchange="showGudang(this.value)">  
<!--                                <option value="none">Select</option>  -->
                                <option value="<%= bean.getIdGudang()%>"><%= bean.getNamaGudang()%></option>  
                                <%
                                    DBClass dbobject2 = new DBClass();
                                    List list3 = dbobject2.getGudang();
                                    request.setAttribute("list", list3);
                                    List list4 = (List) request.getAttribute("list");
                                    if (list4 != null) {
                                        for (int i = 0; i < list4.size(); i++) {
                                            UserBean ubean = (UserBean) list4.get(i);
                                %>
                                
                                <option value="<%=ubean.getIdGgudang()%>"><%= ubean.getNamaGudang()%></option>  
                                <%
                                        }
                                    }
                                %>
                            </select>  

                        </TD>

                    </TR>
                    <TR>
                        <TD width="150px">Tahun Dibuat :</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="thnDibuat" value="<%=bean.getThnDibuat()%>">
                        </TD>

                    </TR>
                    <TR>
                        <TD width="150px">Tahun Dibeli:</TD>
                        <TD>
                            <INPUT TYPE="text" NAME="thnDibeli" value="<%=bean.getThnDibeli()%>">
                        </TD>


                    </TR>
                    <TR>
                        <TD width="150px">Status:</TD>
                        <TD>
                            <select name='status' onchange="showStatus(this.value)">  
                                <option value="<%= bean.getStatus()%>"><%= bean.getNamaStatus()%></option>  

                                
                                <%
                                    DBClass dbobject3 = new DBClass();
                                    List list6 = dbobject3.getStatus();
                                    request.setAttribute("list", list6);
                                    List list7 = (List) request.getAttribute("list");
                                    if (list7 != null) {
                                        for (int i = 0; i < list7.size(); i++) {
                                            UserBean ubean = (UserBean) list7.get(i);
                                %>
                                <option value="<%=ubean.getIdStatus()%>"><%= ubean.getNamaStatus()%></option>  
                             
                                <%
                                        }
                                    }
                                %>
                                
                            </select>  


                    </TR>
                    <TR>
                        <TD colspan="2" align="center">

                            <INPUT TYPE="submit" class="btn btn-primary" value="<%=bean.getAction()%>" name="action"></input>

                            <a class="btn btn-default" href="ControllerServlet?action=cancel2">Cancel</a>

                        </TD>
                        <TD>
                            &nbsp;
                        </TD>
                    </TR>

                </TABLE>

            </form>

        </center>
    </body>
</html>
